// 替换为你的API Key  
const API_KEY = '206574d09255d9790216c87067c48042';  
const CITY = 'Shanghai'; // 默认城市  

// 获取DOM元素  
const cityElement = document.getElementById('city');  
const tempElement = document.getElementById('temp');  
const humidityElement = document.getElementById('humidity');  
const iconElement = document.getElementById('weather-icon');  

// 调用OpenWeatherMap API  
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${CITY}&appid=${API_KEY}&units=metric`)  
    .then(response => response.json())  
    .then(data => {  
        // 更新页面数据  
        cityElement.textContent = data.name;  
        tempElement.textContent = data.main.temp.toFixed(1);  
        humidityElement.textContent = data.main.humidity;  
        // 显示天气图标  
        const iconCode = data.weather[0].icon;  
        iconElement.src = `https://openweathermap.org/img/wn/${iconCode}@2x.png`;  
    })  
    .catch(error => {  
        console.error('获取天气数据失败:', error);  
        cityElement.textContent = '数据加载失败';  
    });  